package cn.iocoder.yudao.module.blog.controller.app.component;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.blog.controller.admin.component.vo.BlogComponentRespVO;
import cn.iocoder.yudao.module.blog.convert.component.BlogComponentConvert;
import cn.iocoder.yudao.module.blog.dal.dataobject.component.BlogComponentDO;
import cn.iocoder.yudao.module.blog.service.component.BlogComponentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 APP - 置顶组件")
@RestController
@RequestMapping("/blog/component")
@Validated
@Slf4j
public class AppBlogComponent {

    @Resource
    private BlogComponentService componentService;

    @GetMapping("/list")
    @Parameter(name = "type", description = "类型", required = true, example = "find")
    @Operation(summary = "获得置顶案例")
    public CommonResult<List<BlogComponentRespVO>> getComponent(@RequestParam("type") String type) {
        List<BlogComponentDO> list = componentService.getAll(type);
        return success(BlogComponentConvert.INSTANCE.convertList(list));
    }
}
